﻿/*
 * Copyright 2009 Aaron Clauson (aaron@sipsorcery.com)
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using NSsh.Common.Utility;

namespace NSsh.Server.ChannelLayer.Console {

    /// <summary>
    /// This class uses an in memory stream to simulate a shell console. It echoes 
    /// back anything it receives on standard input to standard output. The purpose
    /// of this behavour is to provide an easy way to test the SSH server to make sure
    /// the intialisation and encrypted channel are functioning correctly.
    /// </summary>
    public class EchoConsole : IConsole {

        private EchoStream m_echoStream = new EchoStream();
        private EchoStream m_errorStream = new EchoStream();

        public TextWriter StandardInput {get; private set; }
        public TextReader StandardOutput {get; private set;}
        public TextReader StandardError { get; private set;}
        public bool HasClosed { get; private set;}

        public event EventHandler Closed;

        public EchoConsole() {
            StandardInput = new StreamWriter(m_echoStream);
            StandardOutput = new StreamReader(m_echoStream);
            StandardError = new StreamReader(m_errorStream);
        }

        public void Close() {
            m_echoStream.Close();
            m_errorStream.Close();
        }
    }
}
